<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-${model.modelL}-edit" th:object="${${model.modelL}}">
          
#foreach($field in $fieldList)
#if(${field.inputType}!="none")
#if($field.inputType=="hidden")
  <input id="${field.field}" name="${field.field}" th:field="*{${field.field}}"  type="hidden">
#elseif($field.inputType=="date")
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
		<div class="col-sm-8">
		    <div class="input-group"> <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
		       <input type="text" id="${field.field}" name="${field.field}" class="form-control" th:value="${#calendars.format(${model.modelL}.${field.field},'yyyy-MM-dd')}" placeholder="yyyy-MM-dd">
		    </div>
		</div>
		</div>
#elseif($field.inputType=="time")
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
		<div class="col-sm-8">
		    <div class="input-group"> <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
		       <input type="text" id="${field.field}" name="${field.field}" class="form-control" th:value="${${model.modelL}.${field.field}}" placeholder="HH:mm:ss">
		    </div>
		</div>
		</div>
#elseif($field.inputType=="datetime")
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
		<div class="col-sm-8">
		    <div class="input-group"> <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
		       <input type="text" id="${field.field}" name="${field.field}" class="form-control" th:value="${#calendars.format(${model.modelL}.${field.field},'yyyy-MM-dd HH:mm:ss')}" placeholder="yyyy-MM-dd HH:mm:ss">
		    </div>
		</div>
		</div>
#elseif(${field.inputType}=="file")
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
			<div class="col-sm-8"> 
		          <div>
		          	<img th:src="(${${model.modelL}.${field.field}} == '') ? '/img/profile.jpg' : '/profile/' + ${${model.modelL}.${field.field}}" id="${field.field}_image" class="img-circle" height="60" width="60"/>
		          </div>
		          <div style="width: 80%;float: left;">   
					<input id="${field.field}_uploadfile" name="avatarfile" multiple type="file"> 
					<input type="hidden" name="${field.field}" id="${field.field}_name" th:field="*{${field.field}}"/>
				</div>
				<button type="button" class="btn btn-primary" onclick="javascript:${field.field}_fileUpload()" style="float: right;">上传</button>
		    
		    </div>
		</div> 
#elseif($field.inputType=="htmleditor")
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
			<div class="col-sm-8">
		        <input id="${field.field}" name="${field.field}" type="hidden" th:field="*{${field.field}}">
				<div class="summernote" id="${field.field}_editor"></div>
			</div>
		</div>
#elseif(${field.inputType}=="textarea")
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
			<div class="col-sm-8">
				<textarea rows="6" cols=""  id="${field.field}" name="${field.field}"  th:inline="text" class="form-control">[[*{${field.field}}]]</textarea>
			</div>
		</div>
#elseif(${field.inputType}=="select"&&${field.inputValueOne} == "sys_dept")
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
			<div class="col-sm-8">
			    <input class="form-control" type="text" name="treeName" onclick="selectDeptTree()" readonly="true" id="treeName" th:value="${${model.modelL}.${field.inputValueOneL}.${field.inputValueTwoL}}">
			<input name="${field.field}"  type="hidden"  th:field="*{${field.field}}" id="treeId"/>
			</div>
		</div>
#elseif(${field.inputType}=="radio")
#if(${field.inputValue} == "")
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
			<div class="col-sm-8"> 
		      <div class="onoffswitch">
                         <input type="checkbox" th:checked="${${model.modelL}.${field.field} == 0 ? true : false}" class="onoffswitch-checkbox" id="${field.field}" name="${field.field}" />
                         <label class="onoffswitch-label" for="${field.field}">
                             <span class="onoffswitch-inner"></span>
                             <span class="onoffswitch-switch"></span>
                         </label>
              </div>
            </div>
		</div>
#else
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
		    <div class="col-sm-8">
			    <div class="radio-box" th:each="dict : ${@dict.selectDictData('${field.inputValue}')}">
					<input type="radio" th:id="${dict.dictCode}" name="${field.field}" th:value="${dict.dictValue}" th:field="*{${field.field}}">
					<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
				</div>
			</div>
		</div>
#end 
#elseif(${field.inputType}=="select")
#if(${field.inputValueTwo} == "")
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
			<div class="col-sm-8"> 
		      <select id="${field.field}" name="${field.field}" class="form-control m-b" th:with="type=${@dict.selectDictData('${field.inputValue}')}">
                   <option value="">请选择</option>
                   <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{${field.field}}"></option>
               </select>
            </div>
		</div> 
#elseif(${field.inputValueTwo} != "")
         <div class="form-group">	
		    <label class="col-sm-3 control-label">${field.comment}：</label>
			<div class="col-sm-8"> 
		      <select id="${field.field}" name="${field.field}" class="form-control m-b" th:with="type=${ @${field.inputValueOneU}ServiceImpl.selectAll()}">
                   <option value="">请选择</option>
                   <option th:each="dict : ${type}" th:text="${ dict.${field.inputValueTwoL}}" th:value="${dict.id}" th:field="*{${field.field}}"></option>
               </select>
            </div>
		</div>
#end
#elseif(${field.inputType}=="checkbox")
#if(${field.inputValueTwo} == "")
		<div class="form-group">
			<label class="col-sm-3 control-label">${field.comment}：</label>
			<div class="col-sm-8">
				<label th:each="dict:${@dict.selectDictData('${field.inputValue}')}" class="check-box">
					<input name="${field.field}" type="checkbox" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:checked="${@dict.isDictData(${model.modelL}.${field.field},dict.dictValue)}">
				</label>  
			</div>
		</div>
#elseif(${field.inputValueTwo} != "")
		<div class="form-group">
			<label class="col-sm-3 control-label">${field.comment}：</label>
			<div class="col-sm-8"> 
				<select id="${field.field}" name="${field.field}" class="form-control select2-hidden-accessible" multiple="">
					<option th:each="${ @${field.inputValueOneU}ServiceImpl.selectAll()}" th:text="${ dict.${field.inputValueTwoL}}" th:value="${dict.id}" th:selected="${@dict.isDictData(${model.modelL}.${field.field},dict.id)}"></option>
				</select>
			</div>
		</div>
#end 
#else
            <div class="form-group">	
                <label class="col-sm-3 control-label">${field.comment}：</label>
                <div class="col-sm-8">
                    <input id="${field.field}" name="${field.field}" th:field="*{${field.field}}" class="form-control" type="text" placeholder="请输入${field.comment}">
                </div>
            </div>
#end
#end
#end
            </div>
        </form>
    </div>
    <div th:include="include::footer"></div>
<script type="text/javascript" th:inline="javascript">
	var prefix = ctx + "${model.modulePackage}/${model.modelL}"
	layui.use('laydate', function(){
	  var laydate = layui.laydate;
#foreach($field in $fieldList)
#if(${field.inputType}=="datetime")
  //日期时间选择器
	  laydate.render({
	    elem: '#${field.field}'
	    ,type: 'datetime'
	  });
#elseif(${field.inputType}=="date")
	  laydate.render({
	    elem: '#${field.field}'
	  });
#elseif(${field.inputType}=="time")
	  laydate.render({
	    elem: '#${field.field}'
	    ,type: 'time'
	  });
#end
#end	  
	});
#foreach($field in $fieldList)
#if(${field.inputType}=="file")
	  $(window).load(function() {
	    var ${field.field}_options = {
	        thumbBox: '#${field.field}_thumbBox',
	        spinner: '#${field.field}_spinner',
	        imgSrc: '/profile/' + [[${${model.modelL}.${field.field}}]]
	    }
	    var cropper = $('#${field.field}_imageBox').cropbox(${field.field}_options);
	    $('#${field.field}').on('change',
	    function() {
	        var reader = new FileReader();
	        reader.onload = function(e) {
	            ${field.field}_options.imgSrc = e.target.result;
	            //根据MIME判断上传的文件是不是图片类型
	            if((${field.field}_options.imgSrc).indexOf("image/")==-1){
	                parent.layer.alert("文件格式错误，请上传图片类型,如：JPG,JEPG，PNG后缀的文件。", {icon: 2,title:"系统提示"});
	            } else {
	                cropper = $('#${field.field}_imageBox').cropbox(${field.field}_options);
	            }
	        }
	        reader.readAsDataURL(this.files[0]);
	    })
	    $('#${field.field}_blobSubmit').on('click', function(){
	        var img = cropper.getBlob();
	        var formdata = new FormData();
	        formdata.append("avatarfile", img);
	       // formdata.append("userId", $("#userId").val());
	        $.ajax({
	            url: ctx + "file/uploadImg",
	            data: formdata,
	            type: "post",
	            processData: false,
	            contentType: false,
	            success: function(result) {
	            	if (result.code == "0") {
		            	$.modal.alertSuccess(result.msg);
		            	$("#${field.field}_name").val(result.avatar);
	                }else{
	                	$.modal.alertError(result.msg); 
	                }
	            }
	        })
	    }) 
		$('#${field.field}_btnZoomIn').on('click', function(){
			cropper.zoomIn();
		})
		$('#${field.field}_btnZoomOut').on('click', function(){
			cropper.zoomOut();
		})
	});

#elseif(${field.inputType}=="htmleditor") 
	 $('.summernote').summernote({
		height : '220px',
		lang : 'zh-CN'
	});
	$('#${field.field}_editor').code($("#${field.field}").val());
#end
#end 


	$("#form-${model.modelL}-edit").validate({
		rules:{
#foreach($field in $fieldList)
#if($field.isPk != "Y")
#if(!$field.nullable)
			${field.field}:{
				required:true,
			},
#end
#end
#end
		},
		submitHandler:function(form){
			update();
		}
	});
   function submitHandler() {
       if ($.validate.form()) {
       	update();
       }
   }
	function update() {
#foreach($field in $fieldList) 
#if(${field.inputType}!="none")
#if(${field.inputType}=="select")
		var ${field.field} = $("#${field.field} option:selected").val();
#elseif(${field.inputType}=="radio")
		var ${field.field} = $("input[name='${field.field}']").is(':checked') == true ? 0 : 1;
#elseif(${field.inputType}=="checkbox")
#if(${field.inputValueTwo} == "")
		var ${field.field} = $.form.selectCheckeds("${field.field}");
#elseif(${field.inputValueTwo} != "")
		var ${field.field} = $.form.selectSelects("${field.field}");
#end
#elseif(${field.inputType}=="htmleditor")
		var ${field.field} = $('.summernote').code();
#elseif(${field.inputType}=="textarea")
		var ${field.field} = $("#${field.field}").val();
#else
		var ${field.field} = $("input[name='${field.field}']").val();
#end
#end
#end  
		$.ajax({
			cache : true,
			type : "POST",
			url : ctx + "${model.modulePackage}/${model.modelL}/edit",
			data : {
#foreach($field in $fieldList) 
#if(${field.inputType}!="none")
				"${field.field}": ${field.field},
#end
#end
			},
			async : false,
			error : function(request) {
				$.modal.alertError("系统错误");
			},
			success : function(data) {
				$.operate.successCallback(data);
	
			}
		});
	}
	
#foreach($field in $fieldList)
#if(${field.inputValueOne} == "sys_dept")
	/*用户管理-新增-选择部门树*/
		function selectDeptTree() {
	       	var treeId = $("#treeId").val();
	       	var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
	       	var url = ctx + "system/dept/selectDeptTree/" + deptId;
			var options = {
				title: '选择部门',
				width: "380",
				url: ctx + "system/dept/selectDeptTree/" + deptId,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}
		function doSubmit(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
			if ($.tree.notAllowParents(tree)) {
				var body = layer.getChildFrame('body', index);
	   			$("#treeId").val(body.find('#treeId').val());
	   			$("#treeName").val(body.find('#treeName').val());
	   			layer.close(index);
			}
		}
#elseif(${field.inputType}=="file")
	$(document).ready(function(){
	 
	    ${field.field}_fileinputlist();
	});
	
	/** 初始化文件框*/
	function ${field.field}_fileinputlist(){
	    $('#${field.field}_uploadfile').fileinput({
	        language: 'zh', //设置语言
	        showPreview: false,//是否显示预览,不写默认为true
	        showUpload: false, //是否显示上传按钮,跟随文本框的那个
	        showRemove : true, //显示移除按钮,跟随文本框的那个
	        showCaption: true,//是否显示标题,就是那个文本框
	        uploadAsync : false, //默认异步上传
	        elErrorContainer: '#upload-file-errors',
	        maxFileCount: 1, //表示允许同时上传的最大文件个数
	        maxFileSize: 102400,      //单位为kb，如果为0表示不限制文件大小
	        enctype: 'multipart/form-data',
	        dropZoneTitle: '拖拽文件到这里 &hellip;<br>仅仅支持单个文件同时上传',//重新定义提示
	        msgFilesTooMany: '选择上传的文件数量({n}) 超过允许的最大数值{m}！',
	//        allowedFileExtensions: ["xls", "xlsx"],
	        uploadUrl: ctx + "file/uploadImg",
	    });
	}
	
	/*图片上传*/
	function ${field.field}_fileUpload() {
	    //文件默认上传方法,传ID:uploadfile
	    $('#${field.field}_uploadfile').fileinput("upload");
	    //同步上传错误处理
	    $('#${field.field}_uploadfile').on('filebatchuploaderror', function(event, data, msg) {
	        // get message
	        $.modal.alertError(msg); 
	        //重置
	        $('#${field.field}_uploadfile').fileinput("clear");
	        $('#${field.field}_uploadfile').fileinput("reset");
	        $('#${field.field}_uploadfile').fileinput('refresh');
	        $('#${field.field}_uploadfile').fileinput('enable');
	    });
	    //同步上传后从后台返回结果
	    $('#${field.field}_uploadfile').on('filebatchuploadsuccess', function(event, data, previewId, index) {
	        var result = data.response;
	        if (result.code == 0) {
	             $.modal.alertSuccess(result.msg); 
	            $.modalAlert(result.msg,"success"); 
	            $('#${field.field}').val(result.avatar); 
	            $('#${field.field}_image').attr("src","/profile/"+result.avatar); 
	        } else {
	        	$.modal.alertError(result.msg); 
	            //重置
	            $('#${field.field}_uploadfile').fileinput("clear");
	            $('#${field.field}_uploadfile').fileinput("reset");
	            $('#${field.field}_uploadfile').fileinput('refresh');
	            $('#${field.field}_uploadfile').fileinput('enable');
	        }
	    });
	
	}
#end
#end
</script>  
</body>
</html>
